package L617;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: javase
 * @description: 打印1-100的质数
 * @author: luolidong
 * @create: 2021-06-17 16:17
 * @version: 1.0
 */
public class Demo1 {
    public List<Integer> getPrime(int n) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        for (int i = 2; i <= n; i++) {
            if (isPrime(i)) {
                list.add(i);
            }
        }
        return list;
    }

    public boolean isPrime(int x) {
//        for (int i = 2; i < x; i++) {
//        必有一个因子小于等于根号x
        for (int i = 2; i*i <= x; i++) {
            if (x % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        List<Integer> prime = new Demo1().getPrime(1000);
        System.out.println(prime);
    }
}
